<template>
  <div>
    <el-table v-loading="loading" :data="list" style="width: 100%" border>
      <el-table-column width="50" label="序号" header-align="center" align="center">
        <template slot-scope="scope">
          <div>{{$parent.params.per_limit*($parent.params.page-1)+scope.$index+1}}</div>
        </template>
      </el-table-column>
      <el-table-column header-align="center" align="center" prop="id" label="ID" width="60"></el-table-column>
      <el-table-column header-align="center" align="center" prop="order_no" label="订单号" width="220"></el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        prop="out_order_no"
        label="商户订单号"
        width="220"
      ></el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        prop="merchant_no"
        label="商户编号"
        width="170"
      ></el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        prop="sign_name"
        show-overflow-tooltip
        label="签约名"
        width="160"
      ></el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        prop="pay_type"
        label="支付方式"
        width="120"
      ></el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        prop="total_amount"
        label="订单金额（元）"
        width="120"
      ></el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        prop="deducted_amount"
        label="到账金额（元）"
        width="160"
      ></el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        prop="status_name"
        label="订单状态"
        width="130"
      ></el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        prop="dealt_at"
        label="订单完成时间"
        width="140"
      ></el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        prop="created_at"
        label="订单创建时间"
        width="140"
      ></el-table-column>
      <el-table-column header-align="center" align="center" fixed="right" label="操作" width="auto">
        <template slot-scope="scope">
          <el-button
            type="text"
            v-if="scope.row.status===1&&searchInterface('pay_orders.check')"
            @click="checkStatus(scope.row)"
          >校验状态</el-button>
          <el-button
            v-if="scope.row.status===2&&!scope.row.refund_status&&searchInterface('pay_orders.refund')"
            @click="refund(scope.row)"
            type="text"
          >退款</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
// 审核失败

import {
  refund,
  checkOrderStatus
} from '@/api/payment-order-admin/payment-order'
export default {
  props: {
    list: {
      type: Array,
      required: true
    },
    loading: {
      type: Boolean,
      required: true
    },
    status: {
      type: [Number, String],
      required: true
    },
    callback: {
      type: Function,
      required: false
    }
  },
  methods: {
    // 退款
    refund({ id }) {
      this.$confirm('确认发起退款吗?', '订单退款操作？', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          refund(id).then(res => {
            this.$message({
              type: 'success',
              message: '已发起退款，请耐心等待'
            })
            this.callback()
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          })
        })
    },
    // 校验状态
    checkStatus({ id }) {
      checkOrderStatus(id).then(res => {
        this.$message({
          type: 'success',
          message: '已发起订单状态的校验，请稍后查询订单'
        })
      })
    }
  }
}
</script>

<style lang="scss" scoped>
</style>